package com.wzvtc.vsl.securitytool;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Vsl on 2015/3/25.
 */
public class Setup3Activity extends Activity{
    private SharedPreferences sp;
    private EditText et_setup3_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup3);

        et_setup3_phone = (EditText) findViewById(R.id.et_setup3_phone);
        sp = getSharedPreferences("config", MODE_PRIVATE);

        et_setup3_phone.setText(sp.getString("safenumber", ""));
    }

    public void selectContact(View view) {
        Intent intent = new Intent(this, SelectContactActivity.class);
        startActivityForResult(intent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }

        String phone = data.getStringExtra("phone").replace("-", "");
        et_setup3_phone.setText(phone);
    }

    public void next(View view) {
        String phone = et_setup3_phone.getText().toString().trim();
        if (TextUtils.isEmpty(phone)) {
            Toast.makeText(this, "号码未设置", Toast.LENGTH_SHORT).show();
            return;
        }

        SharedPreferences.Editor editor = sp.edit();
        editor.putString("safenumber", phone);
        editor.commit();

        Intent intent = new Intent(Setup3Activity.this, Setup4Activity.class);
        startActivity(intent);
        finish();
    }

    public void pre(View view) {
        Intent intent = new Intent(Setup3Activity.this, Setup2Activity.class);
        startActivity(intent);
        finish();
    }

}
